<template>
  <div>
    <div style="margin-bottom: 10px; font-size: 14px; font-weight: 250; margin-left: 10px">
      <el-icon><Postcard /></el-icon>
      学生课程
    </div>
    <el-card style>
      <el-table :data="data.tableData" stripe style="width: 100%">
        <el-table-column prop="id" label="选课ID" />
        <el-table-column prop="courseName" label="课程名" />
        <el-table-column prop="teacherName" label="教师" />
        <el-table-column prop="credit" label="学分" />
        <el-table-column prop="dailyScore" label="日常成绩" />
        <el-table-column prop="examScore" label="考试成绩" />
        <el-table-column prop="score" label="总成绩" />
        <el-table-column label="操作">
          <template #default="scope">
            <el-button v-if="scope.row.dailyScore == null" @click="deleteCourse(scope.row.id)" type="danger" icon="Delete" circle />
          </template>
        </el-table-column>
      </el-table>
      <div style="display: flex; justify-content: center; margin-top: 10px">
        <el-pagination layout="prev, pager, next" :total="data.tableData.length" :page-size="10" />
      </div>
    </el-card>
  </div>
</template>

<script setup>

import {reactive} from "vue";
import request from "@/utils/request.js";
import {ElMessage} from "element-plus";

const data = reactive({
  tableData: [],
})

const student = JSON.parse(localStorage.getItem("student"))

const load = () => {
  request.get("student/selectAllStudentCourse/" + student.id).then(res => {
    data.tableData = res.data
  })
}

load()

const deleteCourse = (id) => {
  request.delete("student/deleteStudentCourse/" + id).then(res => {
    if (res.code === "200") {
      ElMessage.success("退选成功")
      load()
    } else {
      ElMessage.error(res.msg)
    }
  })
}
</script>